#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
int T;
int n;
int sa[N];
int f[N<<1];
char a[N];
char ans[N];
bool lf;
void dfs(int no,int v){
    if(no==n){
        for(int i=0;i<2*n-1;++i){
            if(i&1){
                int z=i/2;
                int len=0;
                while(a[z+len+1]==a[z-len])++len;
                if(len*2!=f[i])return;
            }
            else{
                int z=i/2;
                int len=0;
                while(a[z+len]==a[z-len])++len;
                if(len*2-1!=f[i])return;
            }
        }
        for(int i=0;i<n-1;++i){
            for(int j=0;j<n;++j){
                if(sa[i]+j>=n)break;
                if(sa[i+1]+j>=n)return;
                if(a[sa[i]+j]<a[sa[i+1]+j])break;
                if(a[sa[i]+j]>a[sa[i+1]+j])return;
            }
        }
        lf=1;
        for(int i=0;i<n;++i){
            if(ans[i]<a[i])break;
            if(a[i]<ans[i]){
                memcpy(ans,a,sizeof(a));
                break;
            }
        }
        return;
    }
    a[sa[no]]='a'+v;
    dfs(no+1,v);
    a[sa[no]]='a'+v+1;
    dfs(no+1,v+1);
}
int main(){
    freopen("string.in","r",stdin);
    freopen("string.out","w",stdout);
    cin>>T;
    while(T--){
        cin>>n;
        lf=0;
        bool fl=1;
        for(int i=0;i<n;++i){
            cin>>sa[i];
            if(sa[i]>=n)fl=0;
        }
        for(int i=0;i<2*n-1;++i){
            cin>>f[i];
            if(f[i]%2==i%2)fl=0;
            if(i&1){
                int z=i/2;
                int len=min(z+1,n-z-1)*2;
                if(f[i]>len)fl=0;
            }
            else{
                int z=i/2;
                int len=min(z,n-1-z)*2+1;
                if(f[i]>len)fl=0;
            }
        }
        if(!fl){
            cout<<"-1\n";
            continue;
        }
        a[n]=100;
        for(int i=0;i<n;++i)ans[i]='z';
        dfs(0,0);
        if(!lf){
            cout<<"-1\n";
            continue;
        }
        for(int i=0;i<n;++i)cout<<ans[i];
        cout<<'\n';
    }
    return 0;
}
